require('dotenv').config();

module.exports = {
  server: {
    port: process.env.PORT || 3000,
    env: process.env.NODE_ENV || 'development'
  },
  
  browser: {
    maxInstances: parseInt(process.env.MAX_BROWSER_INSTANCES) || 2,
    maxConcurrentRequests: parseInt(process.env.MAX_CONCURRENT_REQUESTS) || 4,
    timeout: parseInt(process.env.BROWSER_TIMEOUT) || 30000,
    pageTimeout: parseInt(process.env.PAGE_TIMEOUT) || 15000,
    
    // Puppeteer配置（使用本地Chrome）
    launchOptions: {
      headless: process.env.NODE_ENV === 'production' ? 'new' : false,
      // 使用本地Chrome路径（根据系统自动检测）
      executablePath: process.env.CHROME_PATH || 
        process.platform === 'win32' ? 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe' :
        process.platform === 'darwin' ? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' :
        '/usr/bin/chromium-browser', // Linux
      args: [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-dev-shm-usage',
        '--disable-accelerated-2d-canvas',
        '--no-first-run',
        '--disable-gpu',
        '--disable-web-security',
        '--disable-features=VizDisplayCompositor',
        '--disable-background-timer-throttling',
        '--disable-backgrounding-occluded-windows',
        '--disable-renderer-backgrounding',
        '--disable-field-trial-config',
        '--disable-ipc-flooding-protection'
      ],
      ignoreDefaultArgs: ['--disable-extensions']
    },

    // Playwright配置（使用本地Chrome）
    playwrightOptions: {
      headless: true,
      // 使用本地Chrome
      channel: 'chrome',
      args: [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-dev-shm-usage',
        '--disable-accelerated-2d-canvas',
        '--no-first-run',
        '--disable-gpu',
        '--memory-pressure-off'
      ]
    }
  },
  
  rateLimit: {
    windowMs: parseInt(process.env.RATE_LIMIT_WINDOW_MS) || 60000,
    max: parseInt(process.env.RATE_LIMIT_MAX_REQUESTS) || 30
  },
  
  logging: {
    level: process.env.LOG_LEVEL || 'info',
    file: process.env.LOG_FILE || 'logs/app.log'
  }
};
